package com.king.spark.rdd.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author wdl
 * @Date 2022/11/22 16:34
 */
object Spark_RDD_groupBy {

  def main(args: Array[String]): Unit = {


    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount")

    val sparkContext: SparkContext = new SparkContext(sparkConf)

    val dataRDD = sparkContext.makeRDD(List(1,2,3,4,5),1)
    val dataRDD1 = dataRDD.groupBy(
      _%2
    )
    val value: RDD[(Int, Int)] = dataRDD1.map(v => {
      val a = v._1
      val b = v._2.size
      (a, b)
    })
    value.collect().foreach(println)

    sparkContext.stop()
  }
}
